package com.jhhc.EngineeringSafety.Calculate.Forecast.service.impl;

import com.jhhc.EngineeringSafety.Calculate.Forecast.dao.BDMS_YB_RESULT_M3Mapper;
import com.jhhc.EngineeringSafety.Calculate.Forecast.entity.BDMS_YB_RESULT_M;
import com.jhhc.EngineeringSafety.Calculate.Forecast.service.BDMS_YB_RESULT_M3Service;
import java.util.List;
import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service
public class BDMS_YB_RESULT_M3ServiceImpl
        implements BDMS_YB_RESULT_M3Service
{
    @Resource
    private BDMS_YB_RESULT_M3Mapper bdmsYbResultMDao;
    @Value("${datasourceType}")
    String datasourceType;
    public BDMS_YB_RESULT_M queryById(String cschemeid)
    {
        return this.bdmsYbResultMDao.queryById(cschemeid);
    }

    public Page<BDMS_YB_RESULT_M> queryByPage(BDMS_YB_RESULT_M bdmsYbResultM, PageRequest pageRequest)
    {
        long total = this.bdmsYbResultMDao.count(bdmsYbResultM);
        return new PageImpl(this.bdmsYbResultMDao.queryAllByLimit(bdmsYbResultM, pageRequest), pageRequest, total);
    }

    public List<BDMS_YB_RESULT_M> searchAllByCschemeid(String cschemeid, List<String> stcd, Integer dType)
    {
        return this.bdmsYbResultMDao.searchAllByCschemeid(cschemeid, stcd, dType);
    }

    @Override
    public List<BDMS_YB_RESULT_M> searchAllByCschemeid2(String cschemeid, Integer dType) {
        return bdmsYbResultMDao.searchAllByCschemeid2(cschemeid, dType);
    }

    public int insert(BDMS_YB_RESULT_M bdmsYbResultM)
    {
        if ("mysql".equals(datasourceType)){
            return bdmsYbResultMDao.insertMysql(bdmsYbResultM);
        }else if ("sqlserver".equals(datasourceType)){
            return bdmsYbResultMDao.insert(bdmsYbResultM);
        }
        return 0;

    }

    public BDMS_YB_RESULT_M update(BDMS_YB_RESULT_M bdmsYbResultM)
    {
        this.bdmsYbResultMDao.update(bdmsYbResultM);
        return queryById(bdmsYbResultM.getCschemeid());
    }

    public boolean deleteById(String cschemeid)
    {
        return this.bdmsYbResultMDao.deleteById(cschemeid) > 0;
    }
}
